2020-2021 Sunseeker Telemetry and Lighting System
eusci_a_uart_ex1_loopbackAdvanced.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
61 //******************************************************************************
62 #include "driverlib.h"
63 
64 uint16_t i;
65 uint8_t RXData = 0, TXData = 0;
66 uint8_t check = 0;
67 
68 void main(void)
69 {
70  // stop watchdog
71  WDT_A_hold(WDT_A_BASE);
72 
73  //Set external clock frequency to 32.768 KHz
74  UCS_setExternalClockSource(32768, 0);
75  //Set ACLK=XT1
76  UCS_initClockSignal(UCS_ACLK, UCS_XT1CLK_SELECT, UCS_CLOCK_DIVIDER_1);
77  //Start XT1 with no time out
78  UCS_turnOnLFXT1(UCS_XT1_DRIVE_0, UCS_XCAP_3);
79 
80  //Configure UART pins (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI)
81  //Set P3.0 and P3.1 as Module Function Input
82  GPIO_setAsPeripheralModuleFunctionInputPin(
83  GPIO_PORT_P3,
84  GPIO_PIN0 + GPIO_PIN1
85  );
86 
87  // Configure UART
88  EUSCI_A_UART_initParam param = {0};
89  param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_ACLK;
90  param.clockPrescalar = 3;
91  param.firstModReg = 0;
92  param.secondModReg = 92;
93  param.parity = EUSCI_A_UART_NO_PARITY;
94  param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
95  param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
96  param.uartMode = EUSCI_A_UART_MODE;
97  param.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
98 
99  if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
100  return;
101  }
102 
103  EUSCI_A_UART_enable(EUSCI_A0_BASE);
104 
105  EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
106  EUSCI_A_UART_RECEIVE_INTERRUPT);
107 
108  // Enable USCI_A0 RX interrupt
109  EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
110  EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
111 
112  __enable_interrupt();
113  while (1)
114  {
115  TXData = TXData+1; // Increment TX data
116  // Load data onto buffer
117  EUSCI_A_UART_transmitData(EUSCI_A0_BASE,
118  TXData);
119  while(check != 1);
120  check = 0;
121  }
122 }
123 //******************************************************************************
124 //
125 //This is the USCI_A0 interrupt vector service routine.
126 //
127 //******************************************************************************
128 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
129 #pragma vector=USCI_A0_VECTOR
130 __interrupt
131 #elif defined(__GNUC__)
132 __attribute__((interrupt(USCI_A0_VECTOR)))
133 #endif
134 void EUSCI_A0_ISR(void)
135 {
136  switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
137  {
138  case USCI_NONE: break;
139  case USCI_UART_UCRXIFG:
140  RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
141  if(!(RXData == TXData)) // Check value
142  {
143  while(1);
144  }
145  check =1;
146  break;
147  case USCI_UART_UCTXIFG: break;
148  case USCI_UART_UCSTTIFG: break;
149  case USCI_UART_UCTXCPTIFG: break;
150  }
151 }
void EUSCI_A0_ISR(void)
MPU_initThreeSegmentsParam param
#define STATUS_FAIL
Definition: hw_memmap.h:23